package com.zpc.myvideoserver.common.security.handler;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.zpc.myvideoserver.common.security.pojo.AccountUser;
import com.zpc.myvideoserver.common.security.util.JwtUtil;
import com.zpc.myvideoserver.common.util.ResponseJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @ClassName : LogoutSuccessHandler  //类名
 * @Description : 登出处理类  //描述
 * @Author : zpc20 //作者
 * @Date: 2023/11/2  8:49
 */

@Component
public class LogoutSuccessHandler implements org.springframework.security.web.authentication.logout.LogoutSuccessHandler {

    /**
     * @Name: onLogoutSuccess
     * @Params : [request, response, authentication]:[javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.springframework.security.core.Authentication]
     * @Description : 登出处理类
     * @Author : zpc20
     * @Date : 2023/11/2 8:56
     * @Return void
     * @Throws
     */
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

        if(authentication!=null){
            new SecurityContextLogoutHandler().logout(request,response,authentication);
        }
        ResponseJson.SuccessResponse(response,"登出成功!");
    }
}
